package io.lkt.modules.sys.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

import io.lkt.common.util.Query;
import io.lkt.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.lkt.modules.sys.entity.BUserShieldEntity;
import io.lkt.modules.sys.service.BUserShieldService;
import io.lkt.common.utils.PageUtils;
import io.lkt.common.utils.R;



/**
 * 用户(换成我的)屏蔽表
 *
 * @author xss
 * @email dustwas@163.com
 * @date 2021-09-01 16:00:04
 */
@RestController
@RequestMapping("/sys/busershield")
public class BUserShieldController {
    @Autowired
    private BUserShieldService bUserShieldService;

    @RequestMapping("/getList")
    public R getList(@RequestParam Map<String, Object> params) {
        Query query = new Query(params);
        List<BUserShieldEntity> list = bUserShieldService.getList(query);
        int total = bUserShieldService.getListTotal(query).intValue();

        PageUtils page = new PageUtils(list, total, query.getLimit(), query.getPage());
        return R.ok().put("page", page);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:busershield:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = bUserShieldService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:busershield:info")
    public R info(@PathVariable("id") Integer id){
        BUserShieldEntity bUserShield = bUserShieldService.getById(id);

        return R.ok().put("bUserShield", bUserShield);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//    @RequiresPermissions("sys:busershield:save")
    public R save(@RequestBody BUserShieldEntity bUserShield){
        bUserShield.setCreateTime(new Date());
        bUserShieldService.save(bUserShield);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:busershield:update")
    public R update(@RequestBody BUserShieldEntity bUserShield){
        ValidatorUtils.validateEntity(bUserShield);
        bUserShieldService.updateById(bUserShield);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:busershield:delete")
    public R delete(@RequestBody Integer[] ids){
        bUserShieldService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 根据用户 ID 获取用户的换成我的信息
     * @param userId 用户 ID
     * @return
     */
    @RequestMapping("/userInfo/{userId}")
    public R userInfo(@PathVariable("userId") Integer userId){
        BUserShieldEntity bUserShield = bUserShieldService.getByUserId(userId);

        return R.ok().put("bUserShield", bUserShield);
    }

    @RequestMapping("/deleteByUserId/{userId}")
    public R deleteByUserId(@PathVariable("userId") Integer userId) {
        bUserShieldService.deleteByUserId(userId);
        return R.ok();
    }

}
